<?php
/**
 * Created by PhpStorm.
 * User: zhang
 * Date: 2018/5/4
 * Time: 10:24
 */

namespace app\account\model;

use app\common\model\Base;

class UserManager extends Base{
    const DB_NAME = "user";

    function __construct()
    {
        parent::__construct();
    }

    function getUserName($uid){
        $sql = "select * from user where uid='$uid'";

        return json_encode($this->mysql->selectSQLRow($sql),true);
    }

    function getUserAllInfo($uid){

    }

    protected function getUserByCustom($customKey=[]){
        if(count($customKey) == 0){
            $orderSql = "select * from " .SELF::DB_NAME;
        }else{
            $condition = null;
            foreach ($customKey as $key=>$value){
                //echo "Key: $key; Value: $value<br />\n";
                if($condition==null){
                    $condition = $condition." $key='$value'";
                }else{
                    $condition = $condition." and $key='$value'";
                }

            }

            $orderSql = "select * from " .SELF::DB_NAME. " where " .$condition;
        }

        $data = $this->mysql->selectSQL($orderSql);

        return $data;
    }

    protected function updateUserByCustom($saveCondition,$saveSequence=[]){
        $conditionSql = null;
        $SequencceSql = null;
        foreach ($saveCondition as $key=>$value){
            //echo "Key: $key; Value: $value<br />\n";
            if($conditionSql==null){
                $conditionSql = $conditionSql."$key='$value'";
            }else{
                $conditionSql = $conditionSql." and $key='$value'";
            }
        }

        foreach ($saveSequence as $key=>$value){
            //echo "Key: $key; Value: $value<br />\n";
            if($SequencceSql==null){
                $SequencceSql = $SequencceSql."$key='$value'";
            }else{
                $SequencceSql = $SequencceSql.",$key='$value'";
            }
        }

        $orderSql = "update " .SELF::DB_NAME. " set ".$SequencceSql." where " .$conditionSql;

        return $this->mysql->updateSQL($orderSql);
    }
}